// 引入axios
import request from "@/utils/request"

// 使用枚举存储接口地址
enum Api {
  // 获取spu列表的API
  getSpuListApi = "/admin/product",
  // 添加SPU的API
  saveSpuInfoApi = "/admin/product/saveSpuInfo",
  // 更新SPU的API
  updateSpuInfoApi = "/admin/product/updateSpuInfo",
  // 删除SPU的API
  deleteSpuInfoApi = "/admin/product/deleteSpu",
  // 获取所有trademark数据
  getTrademarkApi = "/admin/product/baseTrademark/getTrademarkList",
  // 获取所有的属性数据
  getBaseSaleAttrApi = "/admin/product/baseSaleAttrList",
  // 获取图片列表
  getSpuImageListApi = "/admin/product/spuImageList",
  // 获取基础销售属性列表
  getSpuSaleAttrListApi = "/admin/product/spuSaleAttrList",
}

// 定义接口函数
// 获取spu列表数据
export const reqGetSpuListData = (
  page: number,
  limit: number,
  category3Id: number
) => {
  return request.get<any, any>(
    Api.getSpuListApi + `/${page}/${limit}?category3Id=${category3Id}`
  )
}

// 添加列表数据
export const reqSaveSpuInfo = (spuInfo) => {
  return request.post<any, any>(Api.saveSpuInfoApi, spuInfo)
}

//修改列表数据
export const reqUpdateSpuInfo = (spuInfo) => {
  return request.post<any, any>(Api.updateSpuInfoApi, spuInfo)
}

//删除列表数据
export const reqDeleteSpuInfo = (spuId: number) => {
  return request.delete(Api.deleteSpuInfoApi + `/${spuId}`)
}

// 获取所有的trademark品牌数据

export const reqGetAllTrademarkList = () => {
  return request.get<any, any>(Api.getTrademarkApi)
}

// 获取所有的销售属性列表数据
export const reqGetBaseSaleAttrList = () => {
  return request.get(Api.getBaseSaleAttrApi)
}

// 获取图片列表
export function reqGetSpuImageList(spuId: number) {
  return request.get<any, any>(Api.getSpuImageListApi + `/${spuId}`)
}

// 获取属性列表
export function reqGetSpuSaleAttrList(spuId: number) {
  return request.get<any, any>(Api.getSpuSaleAttrListApi + `/${spuId}`)
}
